package com.future.doc.excel;


import com.future.doc.util.Resources;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.*;

/**
 * 根据模板导出Excel
 *
 * @author shiyong
 * 2021/8/15 16:42
 */
public class ExportExcelByTemplate {

    public static void main(String[] args) {
        InputStream is = null;
        OutputStream out = null;
        XSSFWorkbook wb = null;

        try {
            is = Resources.getResourceAsStream("/excel/abnormalOperationList.xlsx");
            out = new FileOutputStream("D:/abnormalOperationList.xlsx");
            wb = new XSSFWorkbook(is);

            XSSFSheet sheet = wb.getSheetAt(0);
            int index = 1;

            for (int i = 0; i < 9; i++) {
                XSSFRow row = sheet.createRow(i + 2);
                int column = 0;

                row.createCell(column++).setCellValue(index++);
                row.createCell(column++).setCellValue("ShiftInReason");
                row.createCell(column++).setCellValue("ShiftInDate()");
                row.createCell(column++).setCellValue("ShiftInOffice()");
                row.createCell(column++).setCellValue("ShiftOutReason()");
                row.createCell(column++).setCellValue("ShiftOutDate()");
                row.createCell(column).setCellValue("ShiftOutOffice()");
            }

            wb.write(out);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (wb != null) {
                try {
                    wb.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }



    }
}
